<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Mysql回顾 | YoiaL</title><meta name="keywords" content="学习笔记,菜鸟入门,HTML+CSS"><meta name="author" content="John Doe"><meta name="copyright" content="John Doe"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="回顾本学期课程目标 一、为什么要学习数据库 ​二、数据库的相关概念 ​		DBMS、DB、SQL 三、数据库存储数据的特点 四、初始MySQL  MySQL产品的介绍 MySQL产品的安装          ★ MySQL服务的启动和停止     ★ MySQL服务的登录和退出     ★ MySQL的常见命令和语法规范  五、DQL语言的学习   ★  基础查询	★ 条件查询	★			 排序查询">
<meta property="og:type" content="article">
<meta property="og:title" content="Mysql回顾">
<meta property="og:url" content="https://liaoyia.gitee.io/2020/06/26/MySQL%E5%9F%BA%E7%A1%80/index.html">
<meta property="og:site_name" content="YoiaL">
<meta property="og:description" content="回顾本学期课程目标 一、为什么要学习数据库 ​二、数据库的相关概念 ​		DBMS、DB、SQL 三、数据库存储数据的特点 四、初始MySQL  MySQL产品的介绍 MySQL产品的安装          ★ MySQL服务的启动和停止     ★ MySQL服务的登录和退出     ★ MySQL的常见命令和语法规范  五、DQL语言的学习   ★  基础查询	★ 条件查询	★			 排序查询">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://cdn.jsdelivr.net/gh/liaoyio/imgHosting/img-lymysql.jpg">
<meta property="article:published_time" content="2020-06-26T12:34:53.000Z">
<meta property="article:modified_time" content="2021-03-01T09:04:41.575Z">
<meta property="article:author" content="John Doe">
<meta property="article:tag" content="学习笔记">
<meta property="article:tag" content="菜鸟入门">
<meta property="article:tag" content="HTML+CSS">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://cdn.jsdelivr.net/gh/liaoyio/imgHosting/img-lymysql.jpg"><link rel="shortcut icon" href="/liaoyia/img/favicon.png"><link rel="canonical" href="https://liaoyia.gitee.io/2020/06/26/MySQL%E5%9F%BA%E7%A1%80/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/liaoyia/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/liaoyia/',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: {"defaultEncoding":1,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"簡"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: true,
    post: true
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#121212","position":"bottom-center"},
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: true,
  islazyload: false,
  isanchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = { 
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2021-03-01 17:04:41'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    })(window)</script><link rel="stylesheet" href="/css/fishes.css"><style type="text/css">#toggle-sidebar { left : 100px }</style><meta name="generator" content="Hexo 5.4.0"></head><body><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="author-avatar"><img class="avatar-img" src="/liaoyia/null" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/liaoyia/archives/"><div class="headline">文章</div><div class="length-num">16</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/liaoyia/tags/"><div class="headline">标签</div><div class="length-num">9</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/liaoyia/categories/"><div class="headline">分类</div><div class="length-num">6</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/liaoyia/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fa-fw fas fa-compass"></i><span> 目录</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page" href="/liaoyia/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></li><li><a class="site-page" href="/liaoyia/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></li><li><a class="site-page" href="/liaoyia/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fa-fw fa fa-heartbeat"></i><span> 娱乐</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page" href="/liaoyia/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page" href="/liaoyia/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li><li><a class="site-page" href="/liaoyia/books/"><i class="fa-fw fa fa-book"></i><span> 书籍</span></a></li><li><a class="site-page" href="/liaoyia/games/"><i class="fa-fw fa fa-gamepad"></i><span> 游戏</span></a></li><li><a class="site-page" href="/liaoyia/ziyu/"><i class="fa-fw fa-fw fas fa-cubes"></i><span> 自言自语</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw laptop-code"></i><span> 🎯</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page" href="/liaoyia/messages/"><i class="fa-fw fa-fw fas fa-comment-dots"></i><span> 留言板</span></a></li><li><a class="site-page" href="/liaoyia/link/"><i class="fa-fw fas fa-link"></i><span> Link</span></a></li><li><a class="site-page" href="/liaoyia/about/"><i class="fa-fw fa-fw fas fa-heart"></i><span> 关于我</span></a></li></ul></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://cdn.jsdelivr.net/gh/liaoyio/imgHosting/img-lymysql.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/liaoyia/">YoiaL</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/liaoyia/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fa-fw fas fa-compass"></i><span> 目录</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page" href="/liaoyia/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></li><li><a class="site-page" href="/liaoyia/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></li><li><a class="site-page" href="/liaoyia/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fa-fw fa fa-heartbeat"></i><span> 娱乐</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page" href="/liaoyia/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page" href="/liaoyia/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li><li><a class="site-page" href="/liaoyia/books/"><i class="fa-fw fa fa-book"></i><span> 书籍</span></a></li><li><a class="site-page" href="/liaoyia/games/"><i class="fa-fw fa fa-gamepad"></i><span> 游戏</span></a></li><li><a class="site-page" href="/liaoyia/ziyu/"><i class="fa-fw fa-fw fas fa-cubes"></i><span> 自言自语</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw laptop-code"></i><span> 🎯</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page" href="/liaoyia/messages/"><i class="fa-fw fa-fw fas fa-comment-dots"></i><span> 留言板</span></a></li><li><a class="site-page" href="/liaoyia/link/"><i class="fa-fw fas fa-link"></i><span> Link</span></a></li><li><a class="site-page" href="/liaoyia/about/"><i class="fa-fw fa-fw fas fa-heart"></i><span> 关于我</span></a></li></ul></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Mysql回顾</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2020-06-26T12:34:53.000Z" title="发表于 2020-06-26 20:34:53">2020-06-26</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2021-03-01T09:04:41.575Z" title="更新于 2021-03-01 17:04:41">2021-03-01</time></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">6.2k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>21分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/hint.css/2.4.1/hint.min.css"><h2 id="回顾本学期课程目标">回顾本学期课程目标</h2>
<p><strong>一、为什么要学习数据库</strong><br>
​<strong>二、数据库的相关概念</strong></p>
<p>​		<strong>DBMS、DB、SQL</strong></p>
<p><strong>三、数据库存储数据的特点</strong></p>
<p><strong>四、初始MySQL</strong></p>
<blockquote>
<p>MySQL产品的介绍<br>
MySQL产品的安装          ★<br>
MySQL服务的启动和停止     ★<br>
MySQL服务的登录和退出     ★<br>
MySQL的常见命令和语法规范</p>
</blockquote>
<p><strong>五、DQL语言的学习   ★</strong></p>
<blockquote>
<p>基础查询	★<br>
条件查询	★			<br>
排序查询	★				<br>
常见函数	★<br>
分组函数	★<br>
分组查询	★			<br>
连接查询	★			<br>
子查询		√<br>
分页查询	★<br>
union联合查询		√			<br>
​		<br>
<strong>六、DML语言的学习	★</strong></p>
</blockquote>
<blockquote>
<p>插入语句						<br>
修改语句						<br>
删除语句</p>
</blockquote>
<p><strong>七、DDL语言的学习</strong></p>
<blockquote>
<p>库和表的管理		√				<br>
常见数据类型介绍	√<br>
常见约束			√</p>
</blockquote>
<p><strong>八、TCL语言的学习</strong></p>
<blockquote>
<p>事务和事务处理</p>
</blockquote>
<p><strong>九、视图的讲解		 √</strong></p>
<p><strong>十、变量</strong></p>
<p><strong>十一、存储过程和函数</strong></p>
<p><strong>十二、流程控制结构</strong></p>
<h2 id="数据库的好处">数据库的好处</h2>
<p>​	1.持久化数据到本地<br>
​	2.可以实现结构化查询，方便管理<br>
​</p>
<h2 id="数据库相关概念">数据库相关概念</h2>
<p>​	1、DB：数据库，保存一组有组织的数据的容器<br>
​	2、DBMS：数据库管理系统，又称为数据库软件（产品），用于管理DB中的数据<br>
​	3、SQL:结构化查询语言，用于和DBMS通信的语言</p>
<h2 id="数据库存储数据的特点">数据库存储数据的特点</h2>
<p>1、将数据放到表中，表再放到库中</p>
<p>2、一个数据库中可以有多个表，每个表都有一个的名字，用来标识自己。表名具有唯一性。<br>
​3、表具有一些特性，这些特性定义了数据在表中如何存储，类似java中 “类”的设计。<br>
​	4、表由列组成，我们也称为字段。所有表都是由一个或多个列组成的，每一列类似java 中的”属性”<br>
​<br>
5、表中的数据是按行存储的，每一行类似于java中的“对象”。</p>
<h2 id="MySQL产品的介绍和安装">MySQL产品的介绍和安装</h2>
<h3 id="MySQL服务的启动和停止">MySQL服务的启动和停止</h3>
<p>​	方式一：计算机——右击管理——服务<br>
​	方式二：通过管理员身份运行<br>
​	net start 服务名（启动服务）<br>
​	net stop 服务名（停止服务）</p>
<h3 id="MySQL服务的登录和退出">MySQL服务的登录和退出</h3>
<p>​	方式一：通过mysql自带的客户端<br>
​	只限于root用户</p>
<figure class="highlight plain"><figcaption><span>sql</span></figcaption><table><tr><td class="code"><pre><span class="line">方式二：通过windows自带的客户端</span><br><span class="line">登录：</span><br><span class="line">mysql 【-h主机名 -P端口号 】-u用户名 -p密码</span><br><span class="line"></span><br><span class="line">mysql -h localhost -P 3306 -u root -p</span><br><span class="line">-&gt; Enter password: ****</span><br><span class="line"></span><br><span class="line">退出：</span><br><span class="line">exit或ctrl+C</span><br></pre></td></tr></table></figure>
<h3 id="MySQL的常见命令">MySQL的常见命令</h3>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">1.查看当前所有的数据库</span><br><span class="line">show databases;</span><br><span class="line"></span><br><span class="line">2.打开指定的库</span><br><span class="line">use 库名</span><br><span class="line"></span><br><span class="line">3.查看当前库的所有表</span><br><span class="line">show tables;</span><br><span class="line"></span><br><span class="line">4.查看其它库的所有表</span><br><span class="line">show tables from 库名;</span><br><span class="line"></span><br><span class="line">5.查看当前所在数据库</span><br><span class="line">select database();</span><br><span class="line"></span><br><span class="line">6.创建表</span><br><span class="line">create table 表名(</span><br><span class="line"></span><br><span class="line">	列名 列类型,</span><br><span class="line">	列名 列类型，</span><br><span class="line">	....</span><br><span class="line">);</span><br><span class="line"></span><br><span class="line">7.查看表结构</span><br><span class="line">desc 表名;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">8.查看服务器的版本</span><br><span class="line"></span><br><span class="line">方式一：登录到mysql服务端</span><br><span class="line">select version();</span><br><span class="line"></span><br><span class="line">方式二：没有登录到mysql服务端</span><br><span class="line">mysql --version</span><br><span class="line">或</span><br><span class="line">mysql --V</span><br></pre></td></tr></table></figure>
<h3 id="MySQL的语法规范">MySQL的语法规范</h3>
<p>​	1.不区分大小写,但建议关键字大写，表名、列名小写<br>
​	2.每条命令最好用分号结尾<br>
​	3.每条命令根据需要，可以进行缩进 或换行<br>
​	4.注释<br>
​		单行注释：#注释文字<br>
​		单行注释：-- 注释文字（MySQL中 – 后面需要有空格）<br>
​		多行注释：/* 注释文字  * /<br>
​	<br>
​	<br>
​</p>
<h3 id="SQL的语言分类">SQL的语言分类</h3>
<h5 id="DQL（Data-Query-Language）：数据查询语言">DQL（Data Query Language）：数据查询语言</h5>
<figure class="highlight sql"><table><tr><td class="code"><pre><span class="line"><span class="keyword">select</span> </span><br></pre></td></tr></table></figure>
<h5 id="DML-Data-Manipulate-Language-数据操作语言">DML  (Data Manipulate Language)  :  数据操作语言</h5>
<figure class="highlight sql"><table><tr><td class="code"><pre><span class="line"><span class="keyword">insert</span> 、update、<span class="keyword">delete</span></span><br></pre></td></tr></table></figure>
<h5 id="DDL（Data-Define-Languge）：数据定义语言">DDL（Data Define Languge）：数据定义语言</h5>
<figure class="highlight sql"><table><tr><td class="code"><pre><span class="line"><span class="keyword">create</span>、<span class="keyword">drop</span>、<span class="keyword">alter</span></span><br></pre></td></tr></table></figure>
<h5 id="TCL（Transaction-Control-Language）：事务控制语言">TCL（Transaction Control Language）：事务控制语言</h5>
<figure class="highlight sql"><table><tr><td class="code"><pre><span class="line"><span class="keyword">commit</span>、<span class="keyword">rollback</span></span><br></pre></td></tr></table></figure>
<h3 id="SQL的常见命令">SQL的常见命令</h3>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">show databases； 查看所有的数据库</span><br><span class="line">use 库名； 打开指定 的库</span><br><span class="line">show tables ; 显示库中的所有表</span><br><span class="line">show tables from 库名;显示指定库中的所有表</span><br><span class="line">create table 表名(</span><br><span class="line">	字段名 字段类型,	</span><br><span class="line">	字段名 字段类型</span><br><span class="line">); 创建表</span><br><span class="line"></span><br><span class="line">desc 表名; 查看指定表的结构</span><br><span class="line">select * from 表名;显示表中的所有数据</span><br></pre></td></tr></table></figure>
<h2 id="DQL语言的学习">DQL语言的学习</h2>
<h3 id="进阶1：基础查询">进阶1：基础查询</h3>
<p>​	语法：<br>
​	SELECT 要查询的东西<br>
​	【FROM 表名】;</p>
<pre><code>类似于Java中 :System.out.println(要打印的东西);
</code></pre>
<p>​	特点：<br>
​	①  通过select查询完的结果 ，是一个虚拟的表格，不是真实存在</p>
<p>​	②  要查询的东西 可以是常量值、可以是表达式、可以是字段、可以是函数</p>
<p>​</p>
<h5 id="1-为查询的字段起别名：">1.为查询的字段起别名：</h5>
<blockquote>
<p>便于理解</p>
<p>如果要查询的字段有重名的情况，使用别名可以区分开来.</p>
</blockquote>
<p>​	①  使用 AS</p>
<p>​	②   省略AS 使用空格</p>
<p><code>注意：如果别名存在关键字，需用引号 &quot; &quot;</code></p>
<h5 id="2-去重：">2.去重：</h5>
<p>​	==在字段名前面加上 distinct==</p>
<h5 id="3-号的作用">3. + 号的作用</h5>
<pre><code>java中的 + 号：

① 运算符，两个操作数都为数值型
② 连接符，只要有一个操作数为字符串
</code></pre>
<p>​	MySQL中的 + 号：</p>
<p>​	==<strong>仅仅只有一个功能：运算符</strong>==</p>
<figure class="highlight sql"><table><tr><td class="code"><pre><span class="line"><span class="keyword">select</span> <span class="number">100</span><span class="operator">+</span><span class="number">90</span>;    两个操作数都为数值型，则做加法运算</span><br><span class="line"><span class="keyword">select</span> <span class="string">&#x27;123&#x27;</span><span class="operator">+</span><span class="number">90</span>;  只要其中一方为字符型，试图将字符型数值转换成数值型，如果转换成功，则继续做加法运算</span><br><span class="line"></span><br><span class="line"><span class="keyword">select</span> <span class="string">&#x27;john&#x27;</span><span class="operator">+</span><span class="number">90</span>;	如果转换失败，则将字符型数值转换成<span class="number">0</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">select</span> <span class="keyword">null</span><span class="operator">+</span><span class="number">10</span>;     只要其中一方为<span class="keyword">null</span>，则结果肯定为<span class="keyword">null</span></span><br></pre></td></tr></table></figure>
<p>​	<strong>拼接</strong></p>
<figure class="highlight sql"><table><tr><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> CONCAT(<span class="string">&#x27;a&#x27;</span>,<span class="string">&#x27;b&#x27;</span>,<span class="string">&#x27;c&#x27;</span>) <span class="keyword">AS</span> 结果;</span><br><span class="line"></span><br><span class="line">【案例】：查询员工名和姓连接成一个字段，并显示为 姓名</span><br><span class="line"></span><br><span class="line"><span class="keyword">SELECT</span> </span><br><span class="line">	CONCAT(last_name,first_name) <span class="keyword">AS</span> 姓名</span><br><span class="line"><span class="keyword">FROM</span></span><br><span class="line">	employees;</span><br></pre></td></tr></table></figure>
<p>​</p>
<h6 id="查询字段有null值时无法正确查询解决办法-IFNULL">查询字段有null值时无法正确查询解决办法 (IFNULL)</h6>
<figure class="highlight sql"><table><tr><td class="code"><pre><span class="line">【案例】：显示出表employees的全部列，各个列之间用逗号连接，列头显示成OUT_PUT</span><br><span class="line"></span><br><span class="line"><span class="keyword">SELECT</span></span><br><span class="line">	CONCAT(`first_name`,<span class="string">&#x27;,&#x27;</span>,`last_name`,<span class="string">&#x27;,&#x27;</span>,`job_id`,<span class="string">&#x27;,&#x27;</span>,IFNULL(commission_pct,<span class="number">0</span>)) <span class="keyword">AS</span> out_put</span><br><span class="line"><span class="keyword">FROM</span></span><br><span class="line">	employees;</span><br></pre></td></tr></table></figure>
<p>​</p>
<h3 id="进阶2：条件查询">进阶2：条件查询</h3>
<p>​	条件查询：根据条件过滤原始表的数据，查询到想要的数据<br>
​	语法：<br>
​	select<br>
​		要查询的字段|表达式|常量值|函数<br>
​	from<br>
​		表<br>
​	where<br>
​		条件 ;</p>
<h4 id="分类：">分类：</h4>
<h6 id="一、条件表达式">一、条件表达式</h6>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">示例：salary&gt;10000</span><br><span class="line">条件运算符：</span><br><span class="line">   &gt; &lt; &gt;&#x3D; &lt;&#x3D; &#x3D; !&#x3D; &lt;&gt;</span><br></pre></td></tr></table></figure>
<h6 id="二、逻辑表达式">二、逻辑表达式</h6>
<p>示例：salary&gt;10000 &amp;&amp; salary&lt;20000</p>
<p>逻辑运算符：<br>
作用：用于连接条件表达式</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">and(&amp;&amp;):  两个条件如果同时成立，结果为true，否则为false</span><br><span class="line">or(||):   两个条件只要有一个成立，结果为true，否则为false</span><br><span class="line">not(!):   如果条件成立，则not后为false，否则为true</span><br><span class="line">&gt;&#x3D;90 and &lt;&#x3D;110       # 在90-110之间</span><br><span class="line"> </span><br><span class="line">not(&gt;&#x3D;90 and &lt;&#x3D;110)  # 不在在90-110之间</span><br><span class="line"> </span><br><span class="line">&lt; 90 or &gt; 110    # 不在在90-110之间</span><br></pre></td></tr></table></figure>
<h6 id="三、模糊查询">三、模糊查询</h6>
<blockquote>
<p>Like<br>
between and 在…和…之间<br>
in<br>
is null</p>
</blockquote>
<figure class="highlight sql"><table><tr><td class="code"><pre><span class="line"><span class="number">1.</span><span class="keyword">Like</span></span><br><span class="line">	一般和通配符搭配使用: <span class="operator">%</span> 任意多个字符,包含<span class="number">0</span>个字符、 _ 任意单个字符。</span><br><span class="line">	</span><br><span class="line">	last_name <span class="keyword">like</span> <span class="string">&#x27;%a%&#x27;</span>;</span><br><span class="line">	</span><br><span class="line">	【案例】：查询员工名中第二个字符为_的员工名</span><br><span class="line">	<span class="keyword">SELECT</span> last_name <span class="keyword">FROM</span> employees</span><br><span class="line">	<span class="keyword">WHERE</span></span><br><span class="line">		last_name <span class="keyword">LIKE</span> <span class="string">&#x27;_$_%&#x27;</span> <span class="keyword">ESCAPE</span> <span class="string">&#x27;$&#x27;</span>;  # dscape声明 $ 为转义字符。</span><br><span class="line">	或：直接加在需要转义字符前加上\</span><br><span class="line"></span><br><span class="line"><span class="number">2.</span><span class="keyword">between</span> <span class="keyword">and</span></span><br><span class="line">	包含临界值、两个临界值不要调换顺序</span><br><span class="line">	</span><br><span class="line">	<span class="operator">&gt;=</span><span class="number">100</span> <span class="keyword">and</span> <span class="operator">&lt;=</span><span class="number">120</span>        # 在<span class="number">90</span><span class="number">-110</span>之间</span><br><span class="line">	</span><br><span class="line">	<span class="keyword">between</span> <span class="number">120</span> <span class="keyword">and</span> <span class="number">100</span> （左大右小）   # 在<span class="number">90</span><span class="number">-110</span>之间</span><br><span class="line">	</span><br><span class="line"><span class="number">3.</span><span class="keyword">in</span></span><br><span class="line">	判断某字段的值是否属于<span class="keyword">in</span>列表中的某一项</span><br><span class="line">	注意：<span class="keyword">in</span>列表的值类型必须一致或兼容、<span class="keyword">in</span>列表中不支持通配符</span><br><span class="line">	</span><br><span class="line">案例：查询员工的工种编号是 ui、web、java中的员工名和工种编号.</span><br><span class="line">	<span class="keyword">SELECT</span> last_name,job_id</span><br><span class="line">	<span class="keyword">FROM</span> employees</span><br><span class="line">	<span class="keyword">WHERE</span> job_id <span class="keyword">IN</span>( <span class="string">&#x27;ui&#x27;</span> ,<span class="string">&#x27;web&#x27;</span>,<span class="string">&#x27;java&#x27;</span>);</span><br><span class="line">	</span><br><span class="line"><span class="number">4</span>、<span class="keyword">is</span> <span class="keyword">null</span></span><br><span class="line">	<span class="operator">=</span>或<span class="operator">!=</span>不能用于判断<span class="keyword">null</span>值,需使用<span class="keyword">is</span> <span class="keyword">null</span>或<span class="keyword">is</span> <span class="keyword">not</span> <span class="keyword">null</span>判断<span class="keyword">null</span>值。</span><br><span class="line"></span><br><span class="line">【案例<span class="number">1</span>】：查询没有奖金的员工名和奖金率;</span><br><span class="line"></span><br><span class="line">	<span class="keyword">SELECT</span> last_name,commission_pct</span><br><span class="line">	<span class="keyword">FROM</span> employees</span><br><span class="line">	<span class="keyword">WHERE</span> commission_pct <span class="keyword">IS</span> <span class="keyword">NULL</span>;</span><br><span class="line"></span><br><span class="line">【案例<span class="number">2</span>】：查询有奖金的员工名和奖金率;</span><br><span class="line"></span><br><span class="line">	<span class="keyword">SELECT</span>  last_name,commission_pct</span><br><span class="line">	<span class="keyword">FROM</span> employees</span><br><span class="line">	<span class="keyword">WHERE</span>  commission_pct <span class="keyword">IS</span> <span class="keyword">NOT</span> <span class="keyword">NULL</span>;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">拓展：安全等于  <span class="operator">&lt;=&gt;</span></span><br><span class="line"></span><br><span class="line">【案例<span class="number">1</span>】：查询没有奖金的员工名和奖金率;</span><br><span class="line"></span><br><span class="line">	<span class="keyword">SELECT</span> last_name,commission_pct</span><br><span class="line">	<span class="keyword">FROM</span> employees</span><br><span class="line">	<span class="keyword">WHERE</span> commission_pct <span class="operator">&lt;=&gt;</span><span class="keyword">NULL</span>;</span><br><span class="line">	</span><br><span class="line">	</span><br><span class="line">【案例<span class="number">2</span>】：查询工资为<span class="number">12000</span>的员工信息;</span><br><span class="line"></span><br><span class="line">	<span class="keyword">SELECT</span> last_name,salary</span><br><span class="line">	<span class="keyword">FROM</span> employees</span><br><span class="line">	<span class="keyword">WHERE</span> salary <span class="operator">&lt;=&gt;</span> <span class="number">12000</span>;</span><br><span class="line">	</span><br><span class="line"></span><br><span class="line"><span class="keyword">is</span> <span class="keyword">null</span> 对比 安全等于 <span class="operator">&lt;=&gt;</span></span><br><span class="line"></span><br><span class="line"> 	<span class="keyword">IS</span> <span class="keyword">NULL</span>: 仅仅可以判断<span class="keyword">NULL</span>值，可读性较高，建议使用。</span><br><span class="line"> 	</span><br><span class="line">	<span class="operator">&lt;=&gt;</span>    : 既可以判断<span class="keyword">NULL</span>值，又可以判断普通的数值，可读性较低。</span><br><span class="line">	</span><br><span class="line">练习：</span><br><span class="line"></span><br><span class="line">#查询没有奖金，且工资小于<span class="number">18000</span>的salary,last_name;</span><br><span class="line"></span><br><span class="line">	<span class="keyword">SELECT</span> salary,last_name</span><br><span class="line">	<span class="keyword">FROM</span> employees</span><br><span class="line">	<span class="keyword">WHERE</span> commission_pct <span class="keyword">IS</span> <span class="keyword">NULL</span> </span><br><span class="line">	<span class="keyword">and</span> salary<span class="operator">&lt;</span><span class="number">18000</span>;</span><br><span class="line"></span><br><span class="line">#查询employees表中，job_id不为IT和工资为<span class="number">12000</span>的员工信息。</span><br><span class="line">	<span class="keyword">SELECT</span> <span class="operator">*</span></span><br><span class="line">	<span class="keyword">FROM</span> employees</span><br><span class="line">	<span class="keyword">WHERE</span> job_id<span class="operator">&lt;&gt;</span><span class="string">&#x27;IT&#x27;</span> <span class="keyword">and</span>  salary<span class="operator">=</span><span class="string">&#x27;12000&#x27;</span>;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h3 id="进阶3：排序查询">进阶3：排序查询</h3>
<figure class="highlight sql"><table><tr><td class="code"><pre><span class="line">语法：</span><br><span class="line"><span class="keyword">select</span></span><br><span class="line">	要查询的东西</span><br><span class="line"><span class="keyword">from</span></span><br><span class="line">	表</span><br><span class="line"><span class="keyword">where</span> </span><br><span class="line">	条件</span><br><span class="line"></span><br><span class="line"><span class="keyword">order</span> <span class="keyword">by</span> 排序的字段<span class="operator">|</span>表达式<span class="operator">|</span>函数<span class="operator">|</span>别名 【<span class="keyword">asc</span><span class="operator">|</span><span class="keyword">desc</span>】</span><br></pre></td></tr></table></figure>
<h3 id="进阶4：常见函数">进阶4：常见函数</h3>
<h4 id="一、单行函数">一、单行函数</h4>
<p>​	1、字符函数<br>
​</p>
<figure class="highlight sql"><table><tr><td class="code"><pre><span class="line">	concat  拼接</span><br><span class="line">​	substr  截取子串</span><br><span class="line">​	upper   转换成大写</span><br><span class="line">​	lower   转换成小写</span><br><span class="line">​	trim    去前后指定的空格和字符</span><br><span class="line">​	ltrim   去左边空格</span><br><span class="line">​	rtrim   去右边空格</span><br><span class="line">​	replace 替换</span><br><span class="line">​	lpad    左填充</span><br><span class="line">​	rpad    右填充</span><br><span class="line">​	instr   返回子串第一次出现的索引</span><br><span class="line">​	length  获取字节个数</span><br></pre></td></tr></table></figure>
<p>​	2、数学函数</p>
<figure class="highlight sql"><table><tr><td class="code"><pre><span class="line"></span><br><span class="line">​	round   四舍五入</span><br><span class="line">​	rand    随机数</span><br><span class="line">​	floor   向下取整</span><br><span class="line">​	ceil    向上取整</span><br><span class="line">​	mod     取余</span><br><span class="line">​	<span class="keyword">truncate</span>截断</span><br></pre></td></tr></table></figure>
<p>3、日期函数</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">	now       当前系统日期+时间</span><br><span class="line">​	curdate   当前系统日期</span><br><span class="line">​	curtime   当前系统时间</span><br><span class="line">​	str_to_date 将字符转换成日期</span><br><span class="line">​	date_format 将日期转换成字符</span><br></pre></td></tr></table></figure>
<p>4、流程控制函数</p>
<pre><code>	if 处理双分支

​	case语句 处理多分支
		情况1：处理等值判断
		情况2：处理条件判断
</code></pre>
<p>5、其他函数</p>
<pre><code>	version   版本
​	database  当前库
​	user      当前连接用户
</code></pre>
<h4 id="二、分组函数">二、分组函数</h4>
<pre><code>	sum 求和
	max 最大值
	min 最小值
	avg 平均值
	count 计数


	特点：
	1、以上五个分组函数都忽略null值，除了count(*)
	2、sum和avg一般用于处理数值型
		max、min、count可以处理任何数据类型
    3、都可以搭配distinct使用，用于统计去重后的结果
	4、count的参数可以支持：
		字段、*、常量值，一般放1

	   建议使用 count(*)
</code></pre>
<h2 id="进阶5：分组查询">进阶5：分组查询</h2>
<p>​	语法：<br>
​	select 查询的字段，分组函数<br>
​	from 表<br>
​	group by 分组的字段<br>
​	<br>
​</p>
<pre><code>特点：
1、可以按单个字段分组
2、和分组函数一同查询的字段最好是分组后的字段
3、分组筛选
		针对的表	位置			关键字
分组前筛选：	原始表		group by的前面		where
分组后筛选：	分组后的结果集	group by的后面		having

4、可以按多个字段分组，字段之间用逗号隔开
5、可以支持排序
6、having后可以支持别名
</code></pre>
<h2 id="进阶6：多表连接查询">进阶6：多表连接查询</h2>
<pre><code>笛卡尔乘积：如果连接条件省略或无效则会出现
解决办法：添加上连接条件
</code></pre>
<p>一、传统模式下的连接 ：等值连接——非等值连接</p>
<pre><code>1.等值连接的结果 = 多个表的交集
2.n表连接，至少需要n-1个连接条件
3.多个表不分主次，没有顺序要求
4.一般为表起别名，提高阅读性和性能
</code></pre>
<p>二、sql99语法：通过join关键字实现连接</p>
<pre><code>含义：1999年推出的sql语法
支持：
等值连接、非等值连接 （内连接）
外连接
交叉连接

语法：
</code></pre>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">select 字段，...</span><br><span class="line">from 表1</span><br><span class="line">【inner|left outer|right outer|cross】join 表2 on  连接条件</span><br><span class="line">【inner|left outer|right outer|cross】join 表3 on  连接条件</span><br><span class="line">【where 筛选条件】</span><br><span class="line">【group by 分组字段】</span><br><span class="line">【having 分组后的筛选条件】</span><br><span class="line">【order by 排序的字段或表达式】</span><br></pre></td></tr></table></figure>
<pre><code>好处：语句上，连接条件和筛选条件实现了分离，简洁明了！
</code></pre>
<p>​	<br>
三、自连接</p>
<p>案例：查询员工名和直接上级的名称</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">sql99</span><br><span class="line"></span><br><span class="line">	SELECT e.last_name,m.last_name</span><br><span class="line">	FROM employees e</span><br><span class="line">	JOIN employees m ON e.&#96;manager_id&#96;&#x3D;m.&#96;employee_id&#96;;</span><br></pre></td></tr></table></figure>
<p>sql92</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">SELECT e.last_name,m.last_name</span><br><span class="line">FROM employees e,employees m </span><br><span class="line">WHERE e.&#96;manager_id&#96;&#x3D;m.&#96;employee_id&#96;;</span><br></pre></td></tr></table></figure>
<h2 id="进阶7：子查询">进阶7：子查询</h2>
<p>含义：</p>
<pre><code>一条查询语句中又嵌套了另一条完整的select语句，其中被嵌套的select语句，称为子查询或内查询
在外面的查询语句，称为主查询或外查询
</code></pre>
<p>特点：</p>
<pre><code>1、子查询都放在小括号内
2、子查询可以放在from后面、select后面、where后面、having后面，但一般放在条件的右侧
3、子查询优先于主查询执行，主查询使用了子查询的执行结果
4、子查询根据查询结果的行数不同分为以下两类：
① 单行子查询
	结果集只有一行
	一般搭配单行操作符使用：&gt; &lt; = &lt;&gt; &gt;= &lt;= 
	非法使用子查询的情况：
	a、子查询的结果为一组值
	b、子查询的结果为空
	
② 多行子查询
	结果集有多行
	一般搭配多行操作符使用：any、all、in、not in
	in： 属于子查询结果中的任意一个就行
	any和all往往可以用其他查询代替
</code></pre>
<h2 id="进阶8：分页查询">进阶8：分页查询</h2>
<p>应用场景：</p>
<pre><code>实际的web项目中需要根据用户的需求提交对应的分页查询的sql语句
</code></pre>
<p>语法：</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">select 字段|表达式,...</span><br><span class="line">from 表</span><br><span class="line">【where 条件】</span><br><span class="line">【group by 分组字段】</span><br><span class="line">【having 条件】</span><br><span class="line">【order by 排序的字段】</span><br><span class="line">limit 【起始的条目索引，】条目数;</span><br></pre></td></tr></table></figure>
<p>特点：</p>
<pre><code>1.起始条目索引从0开始

2.limit子句放在查询语句的最后

3.公式：select * from  表 limit （page-1）*sizePerPage,sizePerPage
假如:
每页显示条目数sizePerPage
要显示的页数 page
</code></pre>
<h2 id="进阶9：联合查询">进阶9：联合查询</h2>
<p>引入：<br>
union 联合、合并</p>
<p>语法：</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">select 字段|常量|表达式|函数 【from 表】 【where 条件】 union 【all】</span><br><span class="line">select 字段|常量|表达式|函数 【from 表】 【where 条件】 union 【all】</span><br><span class="line">select 字段|常量|表达式|函数 【from 表】 【where 条件】 union  【all】</span><br><span class="line">.....</span><br><span class="line">select 字段|常量|表达式|函数 【from 表】 【where 条件】</span><br></pre></td></tr></table></figure>
<p>特点：</p>
<pre><code>1、多条查询语句的查询的列数必须是一致的
2、多条查询语句的查询的列的类型几乎相同
3、union代表去重，union all代表不去重
</code></pre>
<h2 id="DML语言">DML语言</h2>
<h3 id="插入">插入</h3>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">语法：</span><br><span class="line">	insert into 表名(字段名，...)</span><br><span class="line">	values(值1，...);</span><br></pre></td></tr></table></figure>
<p>特点：</p>
<pre><code>1、字段类型和值类型一致或兼容，而且一一对应
2、可以为空的字段，可以不用插入值，或用null填充
3、不可以为空的字段，必须插入值
4、字段个数和值的个数必须一致
5、字段可以省略，但默认所有字段，并且顺序和表中的存储顺序一致
</code></pre>
<h3 id="修改">修改</h3>
<p>修改单表语法：</p>
<pre><code>update 表名 set 字段=新值,字段=新值
【where 条件】
</code></pre>
<p>修改多表语法：</p>
<pre><code>update 表1 别名1,表2 别名2
set 字段=新值，字段=新值
where 连接条件
and 筛选条件
</code></pre>
<h3 id="删除">删除</h3>
<p>方式1：delete语句</p>
<p>单表的删除： ★<br>
delete from 表名 【where 筛选条件】</p>
<p>多表的删除：<br>
delete 别名1，别名2<br>
from 表1 别名1，表2 别名2<br>
where 连接条件<br>
and 筛选条件;</p>
<p>方式2：truncate语句</p>
<pre><code>truncate table 表名
</code></pre>
<p>两种方式的区别【面试题】</p>
<pre><code># 1.truncate不能加where条件，而delete可以加where条件

# 2.truncate的效率高一丢丢

# 3.truncate 删除带自增长的列的表后，如果再插入数据，数据从1开始
# delete 删除带自增长列的表后，如果再插入数据，数据从上一次的断点处开始

# 4.truncate删除不能回滚，delete删除可以回滚
</code></pre>
<h2 id="DDL语句">DDL语句</h2>
<h3 id="库和表的管理">库和表的管理</h3>
<p>库的管理：</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">一、创建库</span><br><span class="line">create database 库名</span><br><span class="line">二、删除库</span><br><span class="line">drop database 库名</span><br></pre></td></tr></table></figure>
<p>表的管理：</p>
<h4 id="1-创建表">1.创建表</h4>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">CREATE TABLE IF NOT EXISTS stuinfo(</span><br><span class="line">	stuId INT,</span><br><span class="line">	stuName VARCHAR(20),</span><br><span class="line">	gender CHAR,</span><br><span class="line">	bornDate DATETIME</span><br><span class="line">	);DESC studentinfo;</span><br></pre></td></tr></table></figure>
<h4 id="2-修改表-alter">2.修改表 alter</h4>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">语法：ALTER TABLE 表名 ADD|MODIFY|DROP|CHANGE COLUMN 字段名 【字段类型】;</span><br></pre></td></tr></table></figure>
<h6 id="①修改字段名">①修改字段名</h6>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">ALTER TABLE studentinfo CHANGE  COLUMN sex gender CHAR;</span><br></pre></td></tr></table></figure>
<h6 id="②修改表名">②修改表名</h6>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">ALTER TABLE stuinfo RENAME [TO]  studentinfo;</span><br></pre></td></tr></table></figure>
<h6 id="③修改字段类型和列级约束">③修改字段类型和列级约束</h6>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">ALTER TABLE studentinfo MODIFY COLUMN borndate DATE ;</span><br></pre></td></tr></table></figure>
<h6 id="④添加字段">④添加字段</h6>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">ALTER TABLE studentinfo ADD COLUMN email VARCHAR(20) first;</span><br></pre></td></tr></table></figure>
<h6 id="⑤删除字段">⑤删除字段</h6>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">ALTER TABLE studentinfo DROP COLUMN email;</span><br></pre></td></tr></table></figure>
<h4 id="3-删除表">3.删除表</h4>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">DROP TABLE [IF EXISTS] studentinfo;</span><br></pre></td></tr></table></figure>
<p>​</p>
<h3 id="常见类型">常见类型</h3>
<pre><code>整型：
	
小数：
	浮点型
	定点型
字符型：
日期型：
Blob类型：
</code></pre>
<h3 id="常见约束">常见约束</h3>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">NOT NULL</span><br><span class="line">DEFAULT</span><br><span class="line">UNIQUE</span><br><span class="line">CHECK</span><br><span class="line">PRIMARY KEY</span><br><span class="line">FOREIGN KEY</span><br></pre></td></tr></table></figure>
<h2 id="数据库事务">数据库事务</h2>
<h3 id="含义">含义</h3>
<p>​	通过一组逻辑操作单元（一组DML——sql语句），将数据从一种状态切换到另外一种状态</p>
<h3 id="特点">特点</h3>
<p>​	（ACID）<br>
​	原子性：要么都执行，要么都回滚<br>
​	一致性：保证数据的状态操作前和操作后保持一致<br>
​	隔离性：多个事务同时操作相同数据库的同一个数据时，一个事务的执行不受另外一个事务的干扰<br>
​	持久性：一个事务一旦提交，则数据将持久化到本地，除非其他事务对其进行修改</p>
<p>相关步骤：</p>
<pre><code>1、开启事务
2、编写事务的一组逻辑操作单元（多条sql语句）
3、提交事务或回滚事务
</code></pre>
<h3 id="事务的分类：">事务的分类：</h3>
<p>隐式事务，没有明显的开启和结束事务的标志</p>
<pre><code>比如
insert、update、delete语句本身就是一个事务
</code></pre>
<p>显式事务，具有明显的开启和结束事务的标志</p>
<pre><code>	1、开启事务
	取消自动提交事务的功能
	
	2、编写事务的一组逻辑操作单元（多条sql语句）
	insert
	update
	delete
	
	3、提交事务或回滚事务
</code></pre>
<h3 id="使用到的关键字">使用到的关键字</h3>
<pre><code>set autocommit=0;
start transaction;
commit;
rollback;

savepoint  断点
commit to 断点
rollback to 断点
</code></pre>
<h3 id="事务的隔离级别">事务的隔离级别:</h3>
<p>事务并发问题如何发生？</p>
<pre><code>当多个事务同时操作同一个数据库的相同数据时
</code></pre>
<p>事务的并发问题有哪些？</p>
<pre><code>脏读：一个事务读取到了另外一个事务未提交的数据
不可重复读：同一个事务中，多次读取到的数据不一致
幻读：一个事务读取数据时，另外一个事务进行更新，导致第一个事务读取到了没有更新的数据
</code></pre>
<p>如何避免事务的并发问题？</p>
<pre><code>通过设置事务的隔离级别
1、READ UNCOMMITTED
2、READ COMMITTED 可以避免脏读
3、REPEATABLE READ 可以避免脏读、不可重复读和一部分幻读
4、SERIALIZABLE可以避免脏读、不可重复读和幻读
</code></pre>
<p>设置隔离级别：</p>
<pre><code>set session|global  transaction isolation level 隔离级别名;
</code></pre>
<p>查看隔离级别：</p>
<pre><code>select @@tx_isolation;
</code></pre>
<h2 id="视图">视图</h2>
<p>含义：理解成一张虚拟的表（基表上创建，保存的是定义视图的命令）：</p>
<p>视图和表的区别：</p>
<table>
<thead>
<tr>
<th></th>
<th>使用方式</th>
<th>占用物理空间</th>
</tr>
</thead>
<tbody>
<tr>
<td>试图</td>
<td>完全相同</td>
<td>不占用，仅仅保存的是sql逻辑</td>
</tr>
<tr>
<td>表</td>
<td>完全相同</td>
<td>占用</td>
</tr>
</tbody>
</table>
<p>视图的好处：</p>
<pre><code>1、sql语句提高重用性，效率高
2、和表实现了分离，提高了安全性

---------------------------简单化，屏蔽数据库的复杂性，安全性。
</code></pre>
<h3 id="视图的创建">视图的创建</h3>
<p>​	语法：<br>
​	CREATE VIEW  视图名<br>
​	AS<br>
​	查询语句;</p>
<h3 id="视图的增删改查">视图的增删改查</h3>
<p>​	<code>在命令行模式中，可以用下面命令分辨 表和视图</code></p>
<figure class="highlight sql"><table><tr><td class="code"><pre><span class="line"><span class="keyword">show</span>  <span class="keyword">full</span> tables ;</span><br></pre></td></tr></table></figure>
<p>​	1、查看视图的数据 ★</p>
<figure class="highlight sql"><table><tr><td class="code"><pre><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> my_v4;</span><br><span class="line"><span class="keyword">SELECT</span> <span class="operator">*</span> <span class="keyword">FROM</span> my_v1 <span class="keyword">WHERE</span> last_name<span class="operator">=</span><span class="string">&#x27;Partners&#x27;</span>;</span><br></pre></td></tr></table></figure>
<p>​	2、插入视图的数据</p>
<figure class="highlight sql"><table><tr><td class="code"><pre><span class="line"><span class="keyword">INSERT</span> <span class="keyword">INTO</span> my_v4(last_name,department_id) <span class="keyword">VALUES</span>(<span class="string">&#x27;虚竹&#x27;</span>,<span class="number">90</span>);</span><br></pre></td></tr></table></figure>
<p>​	3、修改视图的数据</p>
<figure class="highlight sql"><table><tr><td class="code"><pre><span class="line">UPDATE my_v4 <span class="keyword">SET</span> last_name <span class="operator">=</span><span class="string">&#x27;梦姑&#x27;</span> <span class="keyword">WHERE</span> last_name<span class="operator">=</span><span class="string">&#x27;虚竹&#x27;</span>;</span><br></pre></td></tr></table></figure>
<p>​	4、删除视图的数据</p>
<figure class="highlight sql"><table><tr><td class="code"><pre><span class="line"><span class="keyword">DELETE</span> <span class="keyword">FROM</span> my_v4;</span><br></pre></td></tr></table></figure>
<p>​	5、删除已创建视图</p>
<figure class="highlight sql"><table><tr><td class="code"><pre><span class="line"><span class="keyword">drop</span> <span class="keyword">view</span> my_v4,my_v5;</span><br></pre></td></tr></table></figure>
<h3 id="某些视图不能更新">某些视图不能更新</h3>
<p>​	包含以下关键字的sql语句：分组函数、distinct、group  by、having、union或者union all<br>
​	常量视图<br>
​	Select中包含子查询<br>
​	join<br>
​	from一个不能更新的视图<br>
​	where子句的子查询引用了from子句中的表</p>
<h3 id="视图逻辑的更新">视图逻辑的更新</h3>
<h3 id="方式一：">方式一：</h3>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">	CREATE OR REPLACE VIEW test_v7</span><br><span class="line">​	AS</span><br><span class="line">​	SELECT last_name FROM employees</span><br><span class="line">​	WHERE employee_id&gt;100;</span><br></pre></td></tr></table></figure>
<h3 id="方式二">方式二:</h3>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">	ALTER VIEW test_v7</span><br><span class="line">​	AS</span><br><span class="line">​	SELECT employee_id FROM employees;</span><br><span class="line">​	</span><br><span class="line">​	SELECT * FROM test_v7;</span><br></pre></td></tr></table></figure>
<h3 id="视图的删除">视图的删除</h3>
<p>​	DROP VIEW test_v1,test_v2,test_v3;</p>
<h3 id="视图结构的查看">视图结构的查看</h3>
<p>​	DESC test_v7;<br>
​	SHOW CREATE VIEW test_v7;</p>
<h2 id="存储过程">存储过程</h2>
<p>含义：一组经过预先编译的sql语句的集合<br>
好处：</p>
<pre><code>1、提高了sql语句的重用性，减少了开发程序员的压力
2、提高了效率
3、减少了传输次数
</code></pre>
<p>分类：</p>
<pre><code>1、无返回无参
2、仅仅带in类型，无返回有参
3、仅仅带out类型，有返回无参
4、既带in又带out，有返回有参
5、带inout，有返回有参
注意：in、out、inout都可以在一个存储过程中带多个
</code></pre>
<h3 id="创建存储过程">创建存储过程</h3>
<p>语法：</p>
<pre><code>create procedure 存储过程名(in|out|inout 参数名  参数类型,...)
begin
	存储过程体

end
</code></pre>
<p>类似于方法：</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">修饰符 返回类型 方法名(参数类型 参数名,...)&#123;</span><br><span class="line"></span><br><span class="line">	方法体;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>注意</p>
<pre><code>1、需要设置新的结束标记
delimiter 新的结束标记
示例：
delimiter $

CREATE PROCEDURE 存储过程名(IN|OUT|INOUT 参数名  参数类型,...)
BEGIN
	sql语句1;
	sql语句2;

END $

2、存储过程体中可以有多条sql语句，如果仅仅一条sql语句，则可以省略begin end

3、参数前面的符号的意思
in:该参数只能作为输入 （该参数不能做返回值）
out：该参数只能作为输出（该参数只能做返回值）
inout：既能做输入又能做输出
</code></pre>
<h4 id="调用存储过程">调用存储过程</h4>
<p>​	call 存储过程名(实参列表)</p>
<h2 id="函数">函数</h2>
<h3 id="创建函数">创建函数</h3>
<p>学过的函数：LENGTH、SUBSTR、CONCAT等<br>
语法：</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">CREATE FUNCTION 函数名(参数名 参数类型,...) RETURNS 返回类型</span><br><span class="line">BEGIN</span><br><span class="line">	函数体</span><br><span class="line"></span><br><span class="line">END</span><br></pre></td></tr></table></figure>
<h3 id="调用函数">调用函数</h3>
<p>​	SELECT 函数名（实参列表）</p>
<h3 id="函数和存储过程的区别">函数和存储过程的区别</h3>
<pre><code>		关键字		调用语法	返回值			应用场景
函数		FUNCTION	SELECT 函数()	只能是一个		一般用于查询结果为一个值并返回时，当有返回值而且仅仅一个
存储过程	PROCEDURE	CALL 存储过程()	可以有0个或多个		一般用于更新
</code></pre>
<h2 id="流程控制结构">流程控制结构</h2>
<h3 id="系统变量">系统变量</h3>
<p>一、全局变量</p>
<p>作用域：针对于所有会话（连接）有效，但不能跨重启</p>
<pre><code>查看所有全局变量
SHOW GLOBAL VARIABLES;
查看满足条件的部分系统变量
SHOW GLOBAL VARIABLES LIKE '%char%';
查看指定的系统变量的值
SELECT @@global.autocommit;
为某个系统变量赋值
SET @@global.autocommit=0;
SET GLOBAL autocommit=0;
</code></pre>
<p>二、会话变量</p>
<p>作用域：针对于当前会话（连接）有效</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">查看所有会话变量</span><br><span class="line">SHOW SESSION VARIABLES;</span><br><span class="line">查看满足条件的部分会话变量</span><br><span class="line">SHOW SESSION VARIABLES LIKE &#39;%char%&#39;;</span><br><span class="line">查看指定的会话变量的值</span><br><span class="line">SELECT @@autocommit;</span><br><span class="line">SELECT @@session.tx_isolation;</span><br><span class="line">为某个会话变量赋值</span><br><span class="line">SET @@session.tx_isolation&#x3D;&#39;read-uncommitted&#39;;</span><br><span class="line">SET SESSION tx_isolation&#x3D;&#39;read-committed&#39;;</span><br></pre></td></tr></table></figure>
<h3 id="自定义变量">自定义变量</h3>
<p>一、用户变量</p>
<p>声明并初始化：</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">SET @变量名&#x3D;值;</span><br><span class="line">SET @变量名:&#x3D;值;</span><br><span class="line">SELECT @变量名:&#x3D;值;</span><br></pre></td></tr></table></figure>
<p>赋值：</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">方式一：一般用于赋简单的值</span><br><span class="line">SET 变量名&#x3D;值;</span><br><span class="line">SET 变量名:&#x3D;值;</span><br><span class="line">SELECT 变量名:&#x3D;值;</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">方式二：一般用于赋表 中的字段值</span><br><span class="line">SELECT 字段名或表达式 INTO 变量</span><br><span class="line">FROM 表;</span><br></pre></td></tr></table></figure>
<p>使用：</p>
<pre><code>select @变量名;
</code></pre>
<p>二、局部变量</p>
<p>声明：</p>
<pre><code>declare 变量名 类型 【default 值】;
</code></pre>
<p>赋值：</p>
<pre><code>方式一：一般用于赋简单的值
SET 变量名=值;
SET 变量名:=值;
SELECT 变量名:=值;


方式二：一般用于赋表 中的字段值
SELECT 字段名或表达式 INTO 变量
FROM 表;
</code></pre>
<p>使用：</p>
<pre><code>select 变量名
</code></pre>
<p>二者的区别：</p>
<pre><code>		作用域			定义位置		语法
</code></pre>
<p>用户变量	当前会话		会话的任何地方		加@符号，不用指定类型<br>
局部变量	定义它的BEGIN END中 	BEGIN END的第一句话	一般不用加@,需要指定类型</p>
<h3 id="分支">分支</h3>
<p>一、if函数<br>
语法：if(条件，值1，值2)<br>
特点：可以用在任何位置</p>
<p>二、case语句</p>
<p>语法：</p>
<pre><code>情况一：类似于switch
case 表达式
when 值1 then 结果1或语句1(如果是语句，需要加分号) 
when 值2 then 结果2或语句2(如果是语句，需要加分号)
...
else 结果n或语句n(如果是语句，需要加分号)
end 【case】（如果是放在begin end中需要加上case，如果放在select后面不需要）

情况二：类似于多重if
case 
when 条件1 then 结果1或语句1(如果是语句，需要加分号) 
when 条件2 then 结果2或语句2(如果是语句，需要加分号)
...
else 结果n或语句n(如果是语句，需要加分号)
end 【case】（如果是放在begin end中需要加上case，如果放在select后面不需要）
</code></pre>
<p>特点：<br>
可以用在任何位置</p>
<p>三、if elseif语句</p>
<p>语法：</p>
<pre><code>if 情况1 then 语句1;
elseif 情况2 then 语句2;
...
else 语句n;
end if;
</code></pre>
<p>特点：<br>
只能用在begin end中！！！！！！！！！！！！！！！</p>
<p>三者比较：<br>
应用场合<br>
if函数		简单双分支<br>
case结构	等值判断 的多分支<br>
if结构		区间判断 的多分支</p>
<h3 id="循环">循环</h3>
<p>语法：</p>
<pre><code>【标签：】WHILE 循环条件  DO
	循环体
END WHILE 【标签】;
</code></pre>
<p>特点：</p>
<pre><code>只能放在BEGIN END里面

如果要搭配leave跳转语句，需要使用标签，否则可以不用标签

leave类似于java中的break语句，跳出所在循环！！！
</code></pre>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:null">John Doe</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://liaoyia.gitee.io/2020/06/26/MySQL%E5%9F%BA%E7%A1%80/">https://liaoyia.gitee.io/2020/06/26/MySQL%E5%9F%BA%E7%A1%80/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://liaoyia.gitee.io" target="_blank">YoiaL</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/liaoyia/tags/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/">学习笔记</a><a class="post-meta__tags" href="/liaoyia/tags/%E8%8F%9C%E9%B8%9F%E5%85%A5%E9%97%A8/">菜鸟入门</a><a class="post-meta__tags" href="/liaoyia/tags/HTML-CSS/">HTML+CSS</a></div><div class="post_share"><div class="social-share" data-image="https://cdn.jsdelivr.net/gh/liaoyio/imgHosting/img-lymysql.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/liaoyia/2020/11/12/hello-world/"><img class="prev-cover" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="onerror=null;src='/liaoyia/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">Hello World</div></div></a></div><div class="next-post pull-right"><a href="/liaoyia/2020/06/22/css%E5%B1%82%E5%8F%A0%E6%A0%B7%E5%BC%8F%E8%A1%A8/"><img class="next-cover" src="https://cdn.jsdelivr.net/gh/liaoyio/imgHosting/img-lyHTML.png" onerror="onerror=null;src='/liaoyia/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">Css层叠样式表期末复习</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span> 相关推荐</span></div><div class="relatedPosts-list"><div><a href="/liaoyia/2020/06/22/css层叠样式表/" title="Css层叠样式表期末复习"><img class="cover" src="https://cdn.jsdelivr.net/gh/liaoyio/imgHosting/img-lyHTML.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-06-22</div><div class="title">Css层叠样式表期末复习</div></div></a></div><div><a href="/liaoyia/2020/04/29/MySQL表查询实训笔记/" title="MySQL表查询实训"><img class="cover" src="https://cdn.jsdelivr.net/gh/liaoyio/imgHosting/img-lymonvpng.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-04-29</div><div class="title">MySQL表查询实训</div></div></a></div><div><a href="/liaoyia/2020/04/09/MySQL数据更新/" title="MySQL数据更新和单表查询"><img class="cover" src="https://cdn.jsdelivr.net/gh/liaoyio/imgHosting/img-lysee.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-04-09</div><div class="title">MySQL数据更新和单表查询</div></div></a></div><div><a href="/liaoyia/2020/04/08/Markdown/" title="Markdown基本语法总结"><img class="cover" src="https://cdn.jsdelivr.net/gh/liaoyio/imgHosting/img-lymd.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-04-08</div><div class="title">Markdown基本语法总结</div></div></a></div><div><a href="/liaoyia/2020/04/06/MySQL数据完整性约束/" title="MySQL数据完整性约束"><img class="cover" src="https://cdn.jsdelivr.net/gh/liaoyio/imgHosting/img-lysel.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-04-06</div><div class="title">MySQL数据完整性约束</div></div></a></div><div><a href="/liaoyia/2020/03/22/MySQL创建和管理数据库/" title="初探 MySQL"><img class="cover" src="https://cdn.jsdelivr.net/gh/liaoyio/imgHosting/img-lymonvpng.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-03-22</div><div class="title">初探 MySQL</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="card-info-avatar is-center"><img class="avatar-img" src="/liaoyia/null" onerror="this.onerror=null;this.src='/liaoyia/img/friend_404.gif'" alt="avatar"/><div class="author-info__name">John Doe</div><div class="author-info__description"></div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/liaoyia/archives/"><div class="headline">文章</div><div class="length-num">16</div></a></div><div class="card-info-data-item is-center"><a href="/liaoyia/tags/"><div class="headline">标签</div><div class="length-num">9</div></a></div><div class="card-info-data-item is-center"><a href="/liaoyia/categories/"><div class="headline">分类</div><div class="length-num">6</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/xxxxxx"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/liaoyio" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="/liaoyia/2417276459" target="_blank" title="QQ"><i class="fas fa-qq"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%9B%9E%E9%A1%BE%E6%9C%AC%E5%AD%A6%E6%9C%9F%E8%AF%BE%E7%A8%8B%E7%9B%AE%E6%A0%87"><span class="toc-number">1.</span> <span class="toc-text">回顾本学期课程目标</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%95%B0%E6%8D%AE%E5%BA%93%E7%9A%84%E5%A5%BD%E5%A4%84"><span class="toc-number">2.</span> <span class="toc-text">数据库的好处</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%95%B0%E6%8D%AE%E5%BA%93%E7%9B%B8%E5%85%B3%E6%A6%82%E5%BF%B5"><span class="toc-number">3.</span> <span class="toc-text">数据库相关概念</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E6%95%B0%E6%8D%AE%E7%9A%84%E7%89%B9%E7%82%B9"><span class="toc-number">4.</span> <span class="toc-text">数据库存储数据的特点</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#MySQL%E4%BA%A7%E5%93%81%E7%9A%84%E4%BB%8B%E7%BB%8D%E5%92%8C%E5%AE%89%E8%A3%85"><span class="toc-number">5.</span> <span class="toc-text">MySQL产品的介绍和安装</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#MySQL%E6%9C%8D%E5%8A%A1%E7%9A%84%E5%90%AF%E5%8A%A8%E5%92%8C%E5%81%9C%E6%AD%A2"><span class="toc-number">5.1.</span> <span class="toc-text">MySQL服务的启动和停止</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#MySQL%E6%9C%8D%E5%8A%A1%E7%9A%84%E7%99%BB%E5%BD%95%E5%92%8C%E9%80%80%E5%87%BA"><span class="toc-number">5.2.</span> <span class="toc-text">MySQL服务的登录和退出</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#MySQL%E7%9A%84%E5%B8%B8%E8%A7%81%E5%91%BD%E4%BB%A4"><span class="toc-number">5.3.</span> <span class="toc-text">MySQL的常见命令</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#MySQL%E7%9A%84%E8%AF%AD%E6%B3%95%E8%A7%84%E8%8C%83"><span class="toc-number">5.4.</span> <span class="toc-text">MySQL的语法规范</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#SQL%E7%9A%84%E8%AF%AD%E8%A8%80%E5%88%86%E7%B1%BB"><span class="toc-number">5.5.</span> <span class="toc-text">SQL的语言分类</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#DQL%EF%BC%88Data-Query-Language%EF%BC%89%EF%BC%9A%E6%95%B0%E6%8D%AE%E6%9F%A5%E8%AF%A2%E8%AF%AD%E8%A8%80"><span class="toc-number">5.5.0.1.</span> <span class="toc-text">DQL（Data Query Language）：数据查询语言</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#DML-Data-Manipulate-Language-%E6%95%B0%E6%8D%AE%E6%93%8D%E4%BD%9C%E8%AF%AD%E8%A8%80"><span class="toc-number">5.5.0.2.</span> <span class="toc-text">DML  (Data Manipulate Language)  :  数据操作语言</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#DDL%EF%BC%88Data-Define-Languge%EF%BC%89%EF%BC%9A%E6%95%B0%E6%8D%AE%E5%AE%9A%E4%B9%89%E8%AF%AD%E8%A8%80"><span class="toc-number">5.5.0.3.</span> <span class="toc-text">DDL（Data Define Languge）：数据定义语言</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#TCL%EF%BC%88Transaction-Control-Language%EF%BC%89%EF%BC%9A%E4%BA%8B%E5%8A%A1%E6%8E%A7%E5%88%B6%E8%AF%AD%E8%A8%80"><span class="toc-number">5.5.0.4.</span> <span class="toc-text">TCL（Transaction Control Language）：事务控制语言</span></a></li></ol></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#SQL%E7%9A%84%E5%B8%B8%E8%A7%81%E5%91%BD%E4%BB%A4"><span class="toc-number">5.6.</span> <span class="toc-text">SQL的常见命令</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#DQL%E8%AF%AD%E8%A8%80%E7%9A%84%E5%AD%A6%E4%B9%A0"><span class="toc-number">6.</span> <span class="toc-text">DQL语言的学习</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%BF%9B%E9%98%B61%EF%BC%9A%E5%9F%BA%E7%A1%80%E6%9F%A5%E8%AF%A2"><span class="toc-number">6.1.</span> <span class="toc-text">进阶1：基础查询</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#1-%E4%B8%BA%E6%9F%A5%E8%AF%A2%E7%9A%84%E5%AD%97%E6%AE%B5%E8%B5%B7%E5%88%AB%E5%90%8D%EF%BC%9A"><span class="toc-number">6.1.0.1.</span> <span class="toc-text">1.为查询的字段起别名：</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#2-%E5%8E%BB%E9%87%8D%EF%BC%9A"><span class="toc-number">6.1.0.2.</span> <span class="toc-text">2.去重：</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#3-%E5%8F%B7%E7%9A%84%E4%BD%9C%E7%94%A8"><span class="toc-number">6.1.0.3.</span> <span class="toc-text">3. + 号的作用</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#%E6%9F%A5%E8%AF%A2%E5%AD%97%E6%AE%B5%E6%9C%89null%E5%80%BC%E6%97%B6%E6%97%A0%E6%B3%95%E6%AD%A3%E7%A1%AE%E6%9F%A5%E8%AF%A2%E8%A7%A3%E5%86%B3%E5%8A%9E%E6%B3%95-IFNULL"><span class="toc-number">6.1.0.3.1.</span> <span class="toc-text">查询字段有null值时无法正确查询解决办法 (IFNULL)</span></a></li></ol></li></ol></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%BF%9B%E9%98%B62%EF%BC%9A%E6%9D%A1%E4%BB%B6%E6%9F%A5%E8%AF%A2"><span class="toc-number">6.2.</span> <span class="toc-text">进阶2：条件查询</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%88%86%E7%B1%BB%EF%BC%9A"><span class="toc-number">6.2.1.</span> <span class="toc-text">分类：</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#%E4%B8%80%E3%80%81%E6%9D%A1%E4%BB%B6%E8%A1%A8%E8%BE%BE%E5%BC%8F"><span class="toc-number">6.2.1.0.1.</span> <span class="toc-text">一、条件表达式</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#%E4%BA%8C%E3%80%81%E9%80%BB%E8%BE%91%E8%A1%A8%E8%BE%BE%E5%BC%8F"><span class="toc-number">6.2.1.0.2.</span> <span class="toc-text">二、逻辑表达式</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#%E4%B8%89%E3%80%81%E6%A8%A1%E7%B3%8A%E6%9F%A5%E8%AF%A2"><span class="toc-number">6.2.1.0.3.</span> <span class="toc-text">三、模糊查询</span></a></li></ol></li></ol></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%BF%9B%E9%98%B63%EF%BC%9A%E6%8E%92%E5%BA%8F%E6%9F%A5%E8%AF%A2"><span class="toc-number">6.3.</span> <span class="toc-text">进阶3：排序查询</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%BF%9B%E9%98%B64%EF%BC%9A%E5%B8%B8%E8%A7%81%E5%87%BD%E6%95%B0"><span class="toc-number">6.4.</span> <span class="toc-text">进阶4：常见函数</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%B8%80%E3%80%81%E5%8D%95%E8%A1%8C%E5%87%BD%E6%95%B0"><span class="toc-number">6.4.1.</span> <span class="toc-text">一、单行函数</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%BA%8C%E3%80%81%E5%88%86%E7%BB%84%E5%87%BD%E6%95%B0"><span class="toc-number">6.4.2.</span> <span class="toc-text">二、分组函数</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%BF%9B%E9%98%B65%EF%BC%9A%E5%88%86%E7%BB%84%E6%9F%A5%E8%AF%A2"><span class="toc-number">7.</span> <span class="toc-text">进阶5：分组查询</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%BF%9B%E9%98%B66%EF%BC%9A%E5%A4%9A%E8%A1%A8%E8%BF%9E%E6%8E%A5%E6%9F%A5%E8%AF%A2"><span class="toc-number">8.</span> <span class="toc-text">进阶6：多表连接查询</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%BF%9B%E9%98%B67%EF%BC%9A%E5%AD%90%E6%9F%A5%E8%AF%A2"><span class="toc-number">9.</span> <span class="toc-text">进阶7：子查询</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%BF%9B%E9%98%B68%EF%BC%9A%E5%88%86%E9%A1%B5%E6%9F%A5%E8%AF%A2"><span class="toc-number">10.</span> <span class="toc-text">进阶8：分页查询</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%BF%9B%E9%98%B69%EF%BC%9A%E8%81%94%E5%90%88%E6%9F%A5%E8%AF%A2"><span class="toc-number">11.</span> <span class="toc-text">进阶9：联合查询</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#DML%E8%AF%AD%E8%A8%80"><span class="toc-number">12.</span> <span class="toc-text">DML语言</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%8F%92%E5%85%A5"><span class="toc-number">12.1.</span> <span class="toc-text">插入</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BF%AE%E6%94%B9"><span class="toc-number">12.2.</span> <span class="toc-text">修改</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%A0%E9%99%A4"><span class="toc-number">12.3.</span> <span class="toc-text">删除</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#DDL%E8%AF%AD%E5%8F%A5"><span class="toc-number">13.</span> <span class="toc-text">DDL语句</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%BA%93%E5%92%8C%E8%A1%A8%E7%9A%84%E7%AE%A1%E7%90%86"><span class="toc-number">13.1.</span> <span class="toc-text">库和表的管理</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1-%E5%88%9B%E5%BB%BA%E8%A1%A8"><span class="toc-number">13.1.1.</span> <span class="toc-text">1.创建表</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-%E4%BF%AE%E6%94%B9%E8%A1%A8-alter"><span class="toc-number">13.1.2.</span> <span class="toc-text">2.修改表 alter</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#%E2%91%A0%E4%BF%AE%E6%94%B9%E5%AD%97%E6%AE%B5%E5%90%8D"><span class="toc-number">13.1.2.0.1.</span> <span class="toc-text">①修改字段名</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#%E2%91%A1%E4%BF%AE%E6%94%B9%E8%A1%A8%E5%90%8D"><span class="toc-number">13.1.2.0.2.</span> <span class="toc-text">②修改表名</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#%E2%91%A2%E4%BF%AE%E6%94%B9%E5%AD%97%E6%AE%B5%E7%B1%BB%E5%9E%8B%E5%92%8C%E5%88%97%E7%BA%A7%E7%BA%A6%E6%9D%9F"><span class="toc-number">13.1.2.0.3.</span> <span class="toc-text">③修改字段类型和列级约束</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#%E2%91%A3%E6%B7%BB%E5%8A%A0%E5%AD%97%E6%AE%B5"><span class="toc-number">13.1.2.0.4.</span> <span class="toc-text">④添加字段</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#%E2%91%A4%E5%88%A0%E9%99%A4%E5%AD%97%E6%AE%B5"><span class="toc-number">13.1.2.0.5.</span> <span class="toc-text">⑤删除字段</span></a></li></ol></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3-%E5%88%A0%E9%99%A4%E8%A1%A8"><span class="toc-number">13.1.3.</span> <span class="toc-text">3.删除表</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B8%B8%E8%A7%81%E7%B1%BB%E5%9E%8B"><span class="toc-number">13.2.</span> <span class="toc-text">常见类型</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B8%B8%E8%A7%81%E7%BA%A6%E6%9D%9F"><span class="toc-number">13.3.</span> <span class="toc-text">常见约束</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%95%B0%E6%8D%AE%E5%BA%93%E4%BA%8B%E5%8A%A1"><span class="toc-number">14.</span> <span class="toc-text">数据库事务</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%90%AB%E4%B9%89"><span class="toc-number">14.1.</span> <span class="toc-text">含义</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%89%B9%E7%82%B9"><span class="toc-number">14.2.</span> <span class="toc-text">特点</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BA%8B%E5%8A%A1%E7%9A%84%E5%88%86%E7%B1%BB%EF%BC%9A"><span class="toc-number">14.3.</span> <span class="toc-text">事务的分类：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8%E5%88%B0%E7%9A%84%E5%85%B3%E9%94%AE%E5%AD%97"><span class="toc-number">14.4.</span> <span class="toc-text">使用到的关键字</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BA%8B%E5%8A%A1%E7%9A%84%E9%9A%94%E7%A6%BB%E7%BA%A7%E5%88%AB"><span class="toc-number">14.5.</span> <span class="toc-text">事务的隔离级别:</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%A7%86%E5%9B%BE"><span class="toc-number">15.</span> <span class="toc-text">视图</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%A7%86%E5%9B%BE%E7%9A%84%E5%88%9B%E5%BB%BA"><span class="toc-number">15.1.</span> <span class="toc-text">视图的创建</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%A7%86%E5%9B%BE%E7%9A%84%E5%A2%9E%E5%88%A0%E6%94%B9%E6%9F%A5"><span class="toc-number">15.2.</span> <span class="toc-text">视图的增删改查</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9F%90%E4%BA%9B%E8%A7%86%E5%9B%BE%E4%B8%8D%E8%83%BD%E6%9B%B4%E6%96%B0"><span class="toc-number">15.3.</span> <span class="toc-text">某些视图不能更新</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%A7%86%E5%9B%BE%E9%80%BB%E8%BE%91%E7%9A%84%E6%9B%B4%E6%96%B0"><span class="toc-number">15.4.</span> <span class="toc-text">视图逻辑的更新</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%96%B9%E5%BC%8F%E4%B8%80%EF%BC%9A"><span class="toc-number">15.5.</span> <span class="toc-text">方式一：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%96%B9%E5%BC%8F%E4%BA%8C"><span class="toc-number">15.6.</span> <span class="toc-text">方式二:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%A7%86%E5%9B%BE%E7%9A%84%E5%88%A0%E9%99%A4"><span class="toc-number">15.7.</span> <span class="toc-text">视图的删除</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%A7%86%E5%9B%BE%E7%BB%93%E6%9E%84%E7%9A%84%E6%9F%A5%E7%9C%8B"><span class="toc-number">15.8.</span> <span class="toc-text">视图结构的查看</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AD%98%E5%82%A8%E8%BF%87%E7%A8%8B"><span class="toc-number">16.</span> <span class="toc-text">存储过程</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E5%AD%98%E5%82%A8%E8%BF%87%E7%A8%8B"><span class="toc-number">16.1.</span> <span class="toc-text">创建存储过程</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E8%B0%83%E7%94%A8%E5%AD%98%E5%82%A8%E8%BF%87%E7%A8%8B"><span class="toc-number">16.1.1.</span> <span class="toc-text">调用存储过程</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%87%BD%E6%95%B0"><span class="toc-number">17.</span> <span class="toc-text">函数</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E5%87%BD%E6%95%B0"><span class="toc-number">17.1.</span> <span class="toc-text">创建函数</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%B0%83%E7%94%A8%E5%87%BD%E6%95%B0"><span class="toc-number">17.2.</span> <span class="toc-text">调用函数</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%87%BD%E6%95%B0%E5%92%8C%E5%AD%98%E5%82%A8%E8%BF%87%E7%A8%8B%E7%9A%84%E5%8C%BA%E5%88%AB"><span class="toc-number">17.3.</span> <span class="toc-text">函数和存储过程的区别</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%B5%81%E7%A8%8B%E6%8E%A7%E5%88%B6%E7%BB%93%E6%9E%84"><span class="toc-number">18.</span> <span class="toc-text">流程控制结构</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%B3%BB%E7%BB%9F%E5%8F%98%E9%87%8F"><span class="toc-number">18.1.</span> <span class="toc-text">系统变量</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%87%AA%E5%AE%9A%E4%B9%89%E5%8F%98%E9%87%8F"><span class="toc-number">18.2.</span> <span class="toc-text">自定义变量</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%86%E6%94%AF"><span class="toc-number">18.3.</span> <span class="toc-text">分支</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%BE%AA%E7%8E%AF"><span class="toc-number">18.4.</span> <span class="toc-text">循环</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/liaoyia/2020/11/12/hello-world/" title="Hello World"><img src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/liaoyia/img/404.jpg'" alt="Hello World"/></a><div class="content"><a class="title" href="/liaoyia/2020/11/12/hello-world/" title="Hello World">Hello World</a><time datetime="2020-11-12T05:23:35.000Z" title="发表于 2020-11-12 13:23:35">2020-11-12</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/liaoyia/2020/06/26/MySQL%E5%9F%BA%E7%A1%80/" title="Mysql回顾"><img src="https://cdn.jsdelivr.net/gh/liaoyio/imgHosting/img-lymysql.jpg" onerror="this.onerror=null;this.src='/liaoyia/img/404.jpg'" alt="Mysql回顾"/></a><div class="content"><a class="title" href="/liaoyia/2020/06/26/MySQL%E5%9F%BA%E7%A1%80/" title="Mysql回顾">Mysql回顾</a><time datetime="2020-06-26T12:34:53.000Z" title="发表于 2020-06-26 20:34:53">2020-06-26</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/liaoyia/2020/06/22/css%E5%B1%82%E5%8F%A0%E6%A0%B7%E5%BC%8F%E8%A1%A8/" title="Css层叠样式表期末复习"><img src="https://cdn.jsdelivr.net/gh/liaoyio/imgHosting/img-lyHTML.png" onerror="this.onerror=null;this.src='/liaoyia/img/404.jpg'" alt="Css层叠样式表期末复习"/></a><div class="content"><a class="title" href="/liaoyia/2020/06/22/css%E5%B1%82%E5%8F%A0%E6%A0%B7%E5%BC%8F%E8%A1%A8/" title="Css层叠样式表期末复习">Css层叠样式表期末复习</a><time datetime="2020-06-22T11:08:56.000Z" title="发表于 2020-06-22 19:08:56">2020-06-22</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/liaoyia/2020/04/29/MySQL%E8%A1%A8%E6%9F%A5%E8%AF%A2%E5%AE%9E%E8%AE%AD%E7%AC%94%E8%AE%B0/" title="MySQL表查询实训"><img src="https://cdn.jsdelivr.net/gh/liaoyio/imgHosting/img-lymonvpng.png" onerror="this.onerror=null;this.src='/liaoyia/img/404.jpg'" alt="MySQL表查询实训"/></a><div class="content"><a class="title" href="/liaoyia/2020/04/29/MySQL%E8%A1%A8%E6%9F%A5%E8%AF%A2%E5%AE%9E%E8%AE%AD%E7%AC%94%E8%AE%B0/" title="MySQL表查询实训">MySQL表查询实训</a><time datetime="2020-04-29T08:21:56.000Z" title="发表于 2020-04-29 16:21:56">2020-04-29</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/liaoyia/2020/04/09/MySQL%E6%95%B0%E6%8D%AE%E6%9B%B4%E6%96%B0/" title="MySQL数据更新和单表查询"><img src="https://cdn.jsdelivr.net/gh/liaoyio/imgHosting/img-lysee.png" onerror="this.onerror=null;this.src='/liaoyia/img/404.jpg'" alt="MySQL数据更新和单表查询"/></a><div class="content"><a class="title" href="/liaoyia/2020/04/09/MySQL%E6%95%B0%E6%8D%AE%E6%9B%B4%E6%96%B0/" title="MySQL数据更新和单表查询">MySQL数据更新和单表查询</a><time datetime="2020-04-09T08:08:56.000Z" title="发表于 2020-04-09 16:08:56">2020-04-09</time></div></div></div></div></div></div></main><footer id="footer" style="background-image: url('https://cdn.jsdelivr.net/gh/liaoyio/imgHosting/img-lymysql.jpg')"><div id="footer-wrap"><div class="copyright">&copy;2018 - 2021 <i style="color:#FF6A6A" class="fa fa-heartbeat"></i> John Doe</div><div class="footer_custom_text">Hi, welcome to my <a target="_blank" rel="noopener" href="https://liaoyi.xyz/">blog</a>!</div></div><div class="container" id="jsi-flying-fish-container"></div><script src="js/fish.js"></script><style>@media only screen and (max-width: 767px){
#sidebar_search_box input[type=text]{width:calc(100% - 24px)}
}</style></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">繁</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div></div><hr/><div id="local-search-results"></div><span class="search-close-button"><i class="fas fa-times"></i></span></div><div id="search-mask"></div></div><div><script src="/liaoyia/js/utils.js"></script><script src="/liaoyia/js/main.js"></script><script src="/liaoyia/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script>function panguFn () {
  if (typeof pangu === 'object') pangu.autoSpacingPage()
  else {
    getScript('https://cdn.jsdelivr.net/npm/pangu/dist/browser/pangu.min.js')
      .then(() => {
        pangu.autoSpacingPage()
      })
  }
}

function panguInit () {
  if (false){
    GLOBAL_CONFIG_SITE.isPost && panguFn()
  } else {
    panguFn()
  }
}

document.addEventListener('DOMContentLoaded', panguInit)</script><script src="/liaoyia/js/search/local-search.js"></script><div class="js-pjax"></div><script src="https://cdn.jsdelivr.net/gh/sviptzk/HexoStaticFile@latest/Hexo/js/mouse_snow.min.js"></script><script src="js/jquery.min.js"></script><script src="/js/fish.js"></script><div class="aplayer no -destroy" data-id="000PeZCQ1i4XVs" data-server="tencent" data-type="artist" data-fixed="true" data-mini=" true" data-listFolded="false" data-order="random" data-preload="none" data-autoplay="true" muted></div><script src="/js/fishes.js"></script><script id="click-heart" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/click-heart.min.js" async="async" mobile="true"></script><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script><script src="https://cdn.jsdelivr.net/gh/metowolf/MetingJS@1.2/dist/Meting.min.js"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>